#!/usr/bin/env python
# -*- coding: utf-8 -*-

from typing import List
from app.requests.reranker_request import RerankerRequest


class RerankerService:
    def __init__(self):
        self.client = RerankerRequest()

    async def rerank_texts(
        self,
        query: str,
        texts: List[str],
        top_k: int = 5
    ) -> List[dict]:
        try:
            res =  await self.client.rerank(
                query=query,
                documents=texts,
                top_n=top_k
            )
            return res["results"]
        except ValueError as e:
            raise ValueError(f"排序服务调用失败: {str(e)}")

